//
//  YoungHisCommentController.m
//  youthNote
//
//  Created by huangrensheng on 15/12/31.
//  Copyright © 2015年 laber. All rights reserved.
//

#import "YoungHisCommentController.h"
#import "YoungHisCell.h"
#import "YoungHisCommentCell.h"

@interface YoungHisCommentController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *commentTable;

@end

@implementation YoungHisCommentController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createWithLeftStyle:@{@"type":@"back"} middleStyle:@{@"type":@"title",@"title":@"详情"} rightStyle:nil];
    self.commentTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.commentTable.delegate = self;
    self.commentTable.dataSource = self;
    self.commentTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.commentTable];
    
    [self.commentTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
}

#pragma mark UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
   return self.contentHeight-40;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *header = [[UIView alloc] init];
    header.backgroundColor = [UIColor whiteColor];
    YoungHisCell *hisCell = [[YoungHisCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
    [header addSubview:hisCell];
    [hisCell mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(header);
    }];
    [hisCell.bottonLine mas_updateConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(hisCell.content.mas_leading);
    }];
    return header;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    __block CGSize textSize = CGSizeZero;
    [UILabel getSizeWithText:@"此外，新的条例将原来的独生子女母亲产假调整为奖励假30天。这意味着，凡符合法律法规规定生育的，不论是生育一孩、还是二孩，以及符合法律法规规定再生育的，都可以享受增加30天产假的优待。同时，丈夫的陪产假从10天增加到15天。" numberOfLine:0 labelWidth:(SCREEN_WIDTH-60) heightLine:0 headerLine:0 labelInfo:^(CGSize size, NSAttributedString *text) {
        textSize = size;
    }];
    return 65+textSize.height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    
    static NSString *indetifer = @"YoungHisCommentCell";
    YoungHisCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:indetifer];
    if (!cell) {
        cell = [[YoungHisCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indetifer];
    }
    return cell;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
